﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DevToolsRepo
{
	public partial class frmEditTool : Form
	{
		private ToolInfo _toolInfo;
		public frmEditTool(ToolInfo toolInfo, bool isAdding)
		{
			InitializeComponent();
			_toolInfo = toolInfo;
			this.Text = isAdding ? "Add Tool" : "Edit Tool";
			Bind();
		}

		public void Bind()
		{
			if (txtName.DataBindings.Count <= 0)
				txtName.DataBindings.Add("Text", _toolInfo, "Name");
			if (txtTags.DataBindings.Count <= 0)
				txtTags.DataBindings.Add("Text", _toolInfo, "TagsSeperated");
			if (txtUrl.DataBindings.Count <= 0)
				txtUrl.DataBindings.Add("Text", _toolInfo, "Url");
			if (txtDescription.DataBindings.Count <= 0)
				txtDescription.DataBindings.Add("Text", _toolInfo, "Description");
			dgVersions.DataSource = null;
			dgVersions.DataSource = _toolInfo.Versions;
		}

		private void mnuAdd_Click(object sender, EventArgs e)
		{
			var ofd = new OpenFileDialog();
			if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				_toolInfo.Versions.Add(new VersionInfo(_toolInfo, new FileInfo(ofd.FileName)));
				Bind();
			}
		}

		private void mnuDelete_Click(object sender, EventArgs e)
		{

		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}
